import { Navigate } from 'react-router-dom'
import { lazy, Suspense } from 'react'


var BookingManagement = lazy(() => import('../../views/Index/BookingManagement'))

var Registration = lazy(() => import('../../views/Index/Booking Management/Registration'))
var Nuclein = lazy(() => import('../../views/Index/Booking Management/Nuclein'))
var Physical = lazy(() => import('../../views/Index/Booking Management/Physical'))
var Arrange = lazy(() => import('../../views/Index/Booking Management/Arrange'))
var Addlist = lazy(() => import('../../views/Index/Booking Management/Addlist.tsx'))
var Looklist = lazy(() => import('../../views/Index/Booking Management/Looklist.tsx'))

var NotFound = lazy(() => import('../../views/NotFound'))

function AuthComponent({ children, permission }) {
    var permissions = localStorage.getItem('userinfo') ?
        JSON.parse(localStorage.getItem('userinfo')).role.permission : [];

    //判断当前用户是否有权限访问该路由对应的组件
    var res = permission && permissions.includes(permission)

    return (
        <Suspense fallback={<div>loading...</div>}>
            {
                res ?
                    children :
                    <NotFound />
            }
        </Suspense>
    )
}

export default [//预约模块的二级路由
    // 预约管理
    {
        path: '/index/bookingmanagement',
        element: <AuthComponent permission={12}><BookingManagement /></AuthComponent>,
        children: [
            {
                path: '/index/bookingmanagement/registration',
                element: <AuthComponent permission={121}><Registration /></AuthComponent>,
            },
            {
                path: '/index/bookingmanagement/nuclein',
                element: <AuthComponent permission={122}><Nuclein /></AuthComponent>,
            },
            {
                path: '/index/bookingmanagement/physical',
                element: <AuthComponent permission={123}><Physical /></AuthComponent>,
            },
            {
                path: '/index/bookingmanagement/arrange',
                element: <AuthComponent permission={124}><Arrange /></AuthComponent>,
            },
            {
                path: '/index/bookingmanagement/addlist',
                element: <Addlist />,
            },
            {
                path: '/index/bookingmanagement/looklist',
                element: <Looklist />,
            }
        ]
    },
]